delphifandomcom-20200223-history
Forum:Please help an ole man
Hi All I am very new to programing and opened Delphi for the first time two weeks ago. I have managed to create a small program on the lines of MS notepad. I have: created a menu and have worked out how toexecute all the relivant dialog boxes, no other menu items work yet, I have inserted a memo (memo1) and it stretches to the window. my problem is that, when I run the prog at the top of the memo box is the text "memo1" and I will be jiggered if I can find out how to clear this when I hit run. Also I cannot work out how to manualy anything. I know this is very basic but I am nearly of pensionable age and feel I want something to tax my small but perfectly formed brain as I get older Thanks Barry ---- :In your form's "OnCreate" event add the following line: memo1.clear; I don't know what you mean by "how to manualy anything". Eddie 18:30, 31 January 2007 (UTC) ::First Select the Memo component on your form. In the object inspector you see all the properties belonging to the Memo component. There's a property called lines. Double click in de box behind it. A property editor will appear. Remove the Memo1 text and run your project. --Xsintill 20:22, 31 January 2007 (UTC) ::Also check out the beginning Delphi page if you want to learn more about Delphi. Thanks Eddie you have been a great help Barry Eddie When I said I did not know how to do anything manualy i ment. adding a dialog box is automatic with the on click plus one line of code to execute. If I wanted to add a procedure manualy I don't know what to add as a declaration or were to pu it, as I said I started programing a few weeks ago. I have not found books or tutorials that go down to something as basic as code layout. Maybe I am a little too old to start programing, what do you thing Eddie? Barry :I think you're never too old to learn. Follow the excellent link provided by Xsintill above, you will find everything you need to know as a beginning Delphi programmer. If you come across something you don't understand, tell us where you read it and why it doesn't make sense to you and we will try to help. :) Eddie 14:55, 1 February 2007 (UTC) Thanks Eddie alos thanks to Xsintill I'm sorry I did not realise the reply was from two different people, I'm also new to forums. A big thank you to both of you :Barry if you like to create a procedure yourself do the following. Start with a file->new application(in delphi 5) or if your using delphi 2005 file->new->VCL Forms Application - Delphi for win32. if your using delphi 5 you wil see the code of unit1 if your using delphi2005 you'll see the visual representation of your form. Hit F12 to toggle between code and the visual presentation. you will see something like this unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} end. now put the following code between the codelines {$R *.DFM} and end. Procedure TForm1.SomeProcedure; begin //Put Your code here end; Now press the following keycombination ctrl-shift-c(class completion). This way delphi creates the declaration of the procedure for you in the class called TForm1 in the private section. This code doesn't do anything yet. remove the commented line //Put Your code here with ShowMessage('Hello World'); ShowMessage will display a little dialog box with an OK button and the text you gave yourself. If you run your application now (F9), you still see nothing happening. Calling this procedure from an event will show the hello world. To do this select Form1: TForm1 in your object inspector(it should already be selected. Now Select the Events tab. Here you can see al kinds of events which can happen while your application is running. We're interested in the OnShow event. Double Click in the box behind it and Delphi creates an event for you. Now put in the following codeline between the begin and end; lines in the newly created event procedure. SomeProcedure; The final code will look like this: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormShow(Sender: TObject); private procedure SomeProcedure; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} Procedure TForm1.SomeProcedure; begin ShowMessage('Hello World'); end; procedure TForm1.FormShow(Sender: TObject); begin SomeProcedure; end; end. Now hit F9 to run your program and you'll see the Hello World message appear. --Xsintill 09:48, 2 February 2007 (UTC) Thanks Xsintill. I have done similar things form the link you gave me, In this one I could not see at first where the "SomeProcedure;" was declared then I noticed "Procedure TForm1.SomeProcedure;" I am presuming that it is a declaration. Fantastic!! by the way the 3D Buss site is great, I'm watching the movies and hopefully learning fast but a problem with it is I can't find a way to enlarge the screen I presume I can't? One question for you and Eddie, "How do I pull in another form" I have created a unit2 Aboutbox and I don't know how to include it in the main prog, I also found an about box in File.. new.. others.. and on the forms tab I found it, but the same problem I don't know how to use it? All the best Barry Barry it is the other way round... The declaration of the procedure is done after the first Uses clause and before the implementation section(in this case its in the private section of class TForm1). The implementation of the procedure is the following code Procedure TForm1.SomeProcedure; begin ShowMessage('Hello World'); end; For your aboutbox problem. If form1 is in unit1 and unit2 has the aboutbox then you should go to unit1 and go to the delphi menu file->'use unit'(alt-F11). A Dialogbox appears with the available units to use for unit1. Choose unit2. in the code editor window for unit1 you can see another uses clause after implementation. Check in unit2 the var section before the implementation section. you'll see the variable name for the aboutbox. now put somewhere in unit1 the following line Aboutbox.Show; Normally you'd put that line under an menuitem's onClick event. Hi Xsintill After following your instructions I ran the "Hello World" code and unsuprisingly it did exactly what you said it would but it also showed me how to use "Events" as indeed you had planned it to. The aboutBox I did manage to get it working, My wife bought me a book called "Inside Delphi" and also needless to say exactly as you have told me above, but your explanation is much easier to follow. Will it be too advanced for me to attempt to make my new about box a component? Barry Barry don't worry about things getting to difficult in the future. Try to get all the basic stuff down first. If you got the basics you can move to other areas like building components. You can MSN or email me at luc_nevilleatbigfoot.com if you want some help. Mind you I'm from the Netherlands so there could be a big time difference. I'm sorry to say I never really tried making components so someone else should step in explaining this, wait a minute Dummzeuch made a nice page on the wiki about Creating Components.--Xsintill 19:31, 2 February 2007 (UTC) You are correct I'll stick to basic's thanks for the Email address I'll pop a hello to you so you get mine, Thanks Barry Xsintill my computer crashed and I have been reinstalling, emailed you today so it shoud be in your inbox, another problem I have been able to get the save dialog to appear but now I need to load the file that I select and display it in memo1, can you point me in the right direction. Thanks Barry memo1.lines.LoadFromFile(opendialog1.filename); Eddie 20:22, 5 February 2007 (UTC) Thanks Eddie that should set me up for all of the dialogs, I stupidly thought that once pulled in they would work silly me Thanks again Barry